/**
 * JAVACC DEMO 1.0
 * @Package com.apache.portal.thread  
 */
package com.apache.portal.thread;

import com.apache.portal.common.util.PortalPubFactory;
import com.apache.rpc.common.LoadRpcService;
import com.apache.rpc.entity.InterfaceRegister;
import com.apache.tools.ConfigUtil;
import com.apache.tools.StrUtil;
import com.apache.uct.common.ToolsUtil;
import org.apache.log4j.Logger;

import java.util.HashMap;
import java.util.Map;

/**
 * description:  【aie项目特有】同步设备状态对接定时任务
 * @author qihan 创建时间：2017-12-28  
 */
public class ErpShebeiAutoSchedulderJob implements ISchedulerJob {

	private Logger log = Logger.getLogger(com.apache.portal.thread.ErpShebeiAutoSchedulderJob.class);
	private static transient boolean ErpShebeiAutoSchedulderJob = true;//线程执行标志

	public void run() {
		if (ErpShebeiAutoSchedulderJob) {
			try {
				ErpShebeiAutoSchedulderJob = false;
				Map<String, Object> param = new HashMap<String, Object>();
				param.put("modelTypes", "s_sysParamManager");
				param.put("resultType", "processSql");
				param.put("sqlKeyId", "aie017");//aie017=（aie）中间表对接设备定时任务插件-ErpShebeiAutoTaskPluginImpl
				param.put("sysPass", ConfigUtil.getInstance().interfacePass());
				param.put("beforMethodKey", "aie017");
				LoadRpcService.service().doServiceClient("aieerpService", "dymicSql", param,
						PortalPubFactory.getInstance().getRpcInfo("ius"));
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				ErpShebeiAutoSchedulderJob = true;
			}
		}
	}

	/**
	 * 进行RPC接口注册的 IP/地址 和 端口的配置定义
	 * @return
	 */
	private InterfaceRegister getInterfaceRegister() {
		InterfaceRegister register = new InterfaceRegister();
		String reqUrl = ConfigUtil.getInstance().getValueByKey("ius_server_url");
		String infoUrl = reqUrl + "/net/service/doService.action";
		if (StrUtil.isNull(reqUrl)) {
			return PortalPubFactory.getInstance().getRpcInfo("net");
		}
		if (reqUrl.startsWith("https:")) {
			register.setCallType("https");
			register.setAddress(infoUrl);
		} else if (reqUrl.startsWith("http:")) {
			register.setCallType("http");
			register.setAddress(infoUrl);
		} else {
			String port = ConfigUtil.getInstance().getValueByKey("ius_server_port");
			register.setAddress(reqUrl);
			register.setPort(port);
			register.setCallType("socket");
		}
		return register;
	}
}
